package com.wsoft.system.controller;

import com.wsoft.response.ResponseResult;
import com.wsoft.system.query.dict.TsDictDataReq;
import com.wsoft.system.query.dict.TsTreeQuery;
import com.wsoft.system.service.ITsDictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 数据字典明细表 前端控制器
 * </p>
 *
 * @author kyle
 * @since 2024年08月29日 14:38:25
 */
@RestController
@Tag(name = "数据字典数据")
@RequestMapping("/ts/dictData")
public class TsDictDataController {
    @Resource
    private ITsDictDataService dictDataService;


    @Operation(summary = "新增字典数据",description = "新增字典数据")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid TsDictDataReq req) {
        boolean b = dictDataService.insert(req);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "编辑字典数据",description = "编辑字典数据")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid TsDictDataReq req) {
        boolean b = dictDataService.update(req);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "删除字典数据",description = "删除字典数据")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = dictDataService.delete(id);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "查看字典数据详情",description = "查看字典数据详情")
    @GetMapping("/get")
    public ResponseResult getDictData(@RequestParam("id") Long id) {
        return ResponseResult.success(dictDataService.getDictData(id));
    }

    @Operation(summary = "根据字典id获取树形字典",description = "根据字典id获取树形字典")
    @PostMapping("/getTreeData")
    public ResponseResult getTreeData(@RequestBody TsTreeQuery treeQuery) {
        return ResponseResult.success(dictDataService.getTreeData(treeQuery));
    }
}
